package com.google.code.coma.gui;

import com.google.code.coma.domain.Part;
import com.google.code.coma.gui.util.ImageUtil;
import com.sun.javafx.scene.layout.region.Border;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.util.Callback;

import javax.xml.soap.Text;

/**
 * @author Dominik Strasser, dominikstr@gmail.com
 */
public class PartCellRender implements Callback<ListView<Part>, ListCell<Part>> {
	@Override
	public ListCell<Part> call(ListView<Part> partListView) {
		return new PartCell();
	}

	static class PartCell extends ListCell<Part> {
		@Override
		public void updateItem(Part item, boolean empty) {
			super.updateItem(item, empty);
			if (item != null) {
				BorderPane border = new BorderPane();
				border.setLeft(new ImageView(ImageUtil.getImage(item.getType())));
				String labelText = item.getType().name();
				if (item.getAppellation() != null)
					labelText += " (" + item.getAppellation() + ")";
				Label label = new Label(labelText);
				label.setAlignment(Pos.CENTER_LEFT);
				border.setCenter(label);
				setGraphic(border);
			}
		}
	}
}
